<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="author" content="https://github.com/thelostword" />
  <title>timeline</title>
</head>
<body>
  <canvas id="Timeline"></canvas>
  <div>
    <span>current time:</span>
    <br>
    <strong id="TimeValue"></strong>

    <br>
    <span>Time Range:</span>
    <br>
    <strong id="TimeRange"></strong>

    <br>
    <span>Number of milliseconds per pixel:</span>
    <br>
    <strong id="MsPerPixel"></strong>
  </div>

  <script type="module">
    import TimeLine, { format } from './dist/timeline.es.js';

    const timezone = 'America/New_York';

    const timeline = new TimeLine('#Timeline', {
      timezone,
      fill: false,
      zoom: 4,
    });

    timeline.draw({
      currentTime: 1651827817000,
      areas: [{
        startTime: 1651827433000,
        endTime: 1651829413000,
        bgColor: '#f897aa'
      },{
        startTime: 1651829533000,
        endTime: 1651832533000,
      }],
    });

    const TimeValue = document.querySelector('#TimeValue');
    TimeValue.textContent = format(timeline.getCurrentTime(), 'YYYY-MM-DD HH:mm:ss', timezone);

    const TimeRange = document.querySelector('#TimeRange');
    const timeRange = timeline.getTimeRange();
    TimeRange.textContent = timeRange ? `${format(timeRange[0], 'YYYY-MM-DD HH:mm:ss', timezone)} ~ ${format(timeRange[1], 'YYYY-MM-DD HH:mm:ss', timezone)}` : 'Undefined';

    const MsPerPixel = document.querySelector('#MsPerPixel');
    MsPerPixel.textContent = `${timeline.getMsPerPixel()} ms`;


    timeline.on('dragged', (timestamp) => {
      TimeValue.textContent = format(timestamp, 'YYYY-MM-DD HH:mm:ss', timezone);

      // update timeRange
      const timeRange = timeline.getTimeRange();
      TimeRange.textContent = timeRange ? `${format(timeRange[0], 'YYYY-MM-DD HH:mm:ss', timezone)} ~ ${format(timeRange[1], 'YYYY-MM-DD HH:mm:ss', timezone)}` : 'Undefined';
    });

    timeline.on('zoom', (zoom) => {
      MsPerPixel.textContent = `${timeline.getMsPerPixel()} ms`;
      console.log(zoom);
    });
    console.log(timeline);
  </script>
</body>
</html>
